package 字符串;


/**
 * @Author Weton Li
 * @Date 2021/4/5 21:39
 */
public class 统计大写字母 {

    public static boolean method(String s){

        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            // 统计大写字母数量
            if (c>='A'&&c<='Z'){
                count++;
            }
        }
        if (count==0 || count==s.length() || count==1&s.charAt(0)>='A'&&s.charAt(0)<='Z') { //'A'=65 'Z'=90
            return true;
        }
        return false;
    }

    public static boolean detectCapitalUse(String word) {
        boolean res = false;
        int count = 0;
        char x;
        for (int i = 0; i < word.length(); i++) {
            x = word.charAt(i);
            if(x >= 65 && x <= 90) {
                count++;
            }
        }
        if ((count == 1 && (word.charAt(0) >= 65 && word.charAt(0) <= 90)) || (count == word.length())||count==0) {
            res = true;
        }
        return res;
    }
    public static void main(String[] args) {
        String input1 = "leetcode";
        String input2 = "Leetcode";
        String input3 = "LEETCODE";
        System.out.println(method(input1));
        System.out.println(method(input2));
        System.out.println(method(input3));
        System.out.println(detectCapitalUse(input1));
        System.out.println(detectCapitalUse(input2));
        System.out.println(detectCapitalUse(input3));

    }
}
